package com.sdjenkins.sms;

import java.util.Date;

import javax.persistence.Column;

public class Sms implements Comparable<Sms>, SmsCore {

	private short protocol = 0;
	private String address;
	private long date;
	private short type;
	private String subject = "null";
	private String body;
	private String toa = "null";
	private String sc_toa = "null";
	private String service_center = "null";
	private short read = 1;
	private short status = -1;

	public Sms() {
		super();
	}
	
	public Sms(SmsCore core) {
		address = core.getAddress();
		body = core.getBody();
		date = core.getDate();
		type = core.getType();
	}
	
	public int compareTo(Sms o) {
		return Long.valueOf(date).compareTo(Long.valueOf(o.getDate()));
	}
	public boolean equals(Object o) {
		boolean isEq = false;
		if (o instanceof Sms) {
			isEq = date == ((Sms) o).date;
		}
		return isEq;
	}
	public String getAddress() {
		return address;
	}
	public String getBody() {
		return body;
	}
	public long getDate() {
		return date;
	}
	public short getProtocol() {
		return protocol;
	}
	public short getRead() {
		return read;
	}
	public String getSc_toa() {
		return sc_toa;
	}
	public String getService_center() {
		return service_center;
	}
	public short getStatus() {
		return status;
	}
	public String getSubject() {
		return subject;
	}
	public String getToa() {
		return toa;
	}
	@Column(name="SMSTYPE")
	public short getType() {
		return type;
	}

	private String getTypeAsIcon() {

		switch (type) {
		case 1:
			return "   => ";
		case 2:
			return " <=   ";
		default:
			return " ???? ";
		}

	}

	public int hashCode() {
		return Long.valueOf(date).intValue();
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public void setDate(long date) {
		this.date = date;
	}

	public void setProtocol(short protocol) {
		this.protocol = protocol;
	}

	public void setRead(short read) {
		this.read = read;
	}

	public void setSc_toa(String sc_toa) {
		this.sc_toa = sc_toa;
	}

	public void setService_center(String service_center) {
		this.service_center = service_center;
	}

	public void setStatus(short status) {
		this.status = status;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public void setToa(String toa) {
		this.toa = toa;
	}

	public void setType(short type) {
		this.type = type;
	}

	public String toString() {
		return new Date(date) + " " + address + getTypeAsIcon() + body + "\n";
	}

}
